package com.example.opengldemo.base;

import android.annotation.SuppressLint;
import android.opengl.GLES30;
import android.view.View;

import com.example.opengldemo.util.MatrixState;
import com.example.opengldemo.util.ShaderBuffer;
import com.example.opengldemo.util.ShaderHandle;
import com.example.opengldemo.util.ShaderResource;
import com.example.opengldemo.util.ShaderUtil;

import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.FloatBuffer;


public class Texture_Rect_Vertex_Normal_Texcoors
{

    ShaderHandle shaderHandle ;
    ShaderBuffer shaderBuffer ;
    GLDrawCut cut ;

    public Texture_Rect_Vertex_Normal_Texcoors(ShaderResource shaderResource, ShaderBuffer shaderBuffer , GLDrawCut cut )
    {    	

        this.shaderBuffer = shaderBuffer ;
        this.cut = cut ;
        shaderHandle = new ShaderHandle(shaderResource.getProgram()) ;
    }
    
    public void drawSelf(int texId)
    {
        shaderHandle.program()
                .bindMVPMaxtrixHandle()
                .bindMMaxtrixHandle();
        if(shaderBuffer.getVertexBuffer() != null){
            shaderHandle.bindVertexHandle(shaderBuffer.getVertexBuffer()) ;
        }
        if(shaderBuffer.getNormalBuffer() != null){
            shaderHandle.bindNormalHandle(shaderBuffer.getNormalBuffer()) ;
        }
        if(shaderBuffer.getTexcoorBuffer() != null){
            shaderHandle.bindTexCoorsHandle(shaderBuffer.getTexcoorBuffer()) ;
        }

        shaderHandle.bindDefaultTextureHandle(texId) ;

    	 cut.drawRunBefore();

         shaderHandle.run(GLES30.GL_TRIANGLES, shaderBuffer.vCount);

        cut.drawRunAfter();
    }
}
